﻿using System;

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using BLL;
using models;

namespace yuejilalala
{
    public partial class information : System.Web.UI.Page
    {
        UserMarager marager = new UserMarager();
        DateManager dateManager = new DateManager();
        CartMarager cartMarager = new CartMarager();

        User user = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["sess"] == null)
                {
                    Response.Redirect("Login.aspx");
                }
                if (Session["sessid"] != null)
                {

                    J_MiniCartNum.Text = cartMarager.CartCount((Session["sessid"].ToString())).ProPrice.ToString();//显示出购物车内物品.数量
                }
                Userdata();
                nyr();
                userDl();
                if (Session["ddh"]!=null)
                {
                    orderForm.alipayTradeQuery(Session["ddh"].ToString());//订单状态查询
                    orderForm.ifOrderStatus();//判定订单状态
                }
              


            }
        }
        //登陆在左上方显示用户名方法					
        public void userDl()
        {
            if (Session["sess"] != null)
            {
                //用户存在则显示出来 并且隐藏注册和登陆显示
                User user = Session["sess"] as User;
                hl_dlm.Text = "用户名:" + user.UName;
                hl_dlm.Visible = true;//显示登陆名控件
                hl_dl.Visible = false;//请登陆隐藏
                hl_zc.Visible = false;//注册隐藏
            }

        }
        protected void LinkButton4_Click(object sender, EventArgs e)
        {

             user = new User( );
             user.UName= this.tb_uname.Text;
             user.Sex=  RadioButton1.Checked ? "男" : (RadioButton2.Checked ? "女" : "保密");
            user.Birthday= (DropDownList1.SelectedValue.ToString() + "." + DropDownList2.SelectedValue.ToString() + "." + DropDownList3.SelectedValue.ToString()).ToString();
             user.Phone=  decimal.Parse(tb_phone.Text);
            user.Email = tb_email.Text;
            if (marager.updataUsers(user ,HiddenField1.Value))
            {
              
                Session["sess"]= user;
                Response.Redirect("information.aspx");
              
            }
            Response.Write("<script>alert('修改成功')</script>");

        }
        public void nyr()
        {
            List<Yearr> yearrs = dateManager.GetYear();
            DropDownList1.DataSource = yearrs;
            DropDownList1.DataValueField = "year";
            DropDownList1.DataTextField = "year";
            DropDownList1.DataBind();

            List<Monthh> monthhs = dateManager.GetMonthh();
            DropDownList2.DataSource = monthhs;
            DropDownList2.DataValueField = "month";
            DropDownList2.DataTextField = "month";
            DropDownList2.DataBind();

            List<Dayy> dayys = dateManager.GetDay();
            DropDownList3.DataSource = dayys;
            DropDownList3.DataValueField = "day";
            DropDownList3.DataTextField = "day";
            DropDownList3.DataBind();
          

        }
        public void Userdata() 
        {
            User user = Session["sess"] as User;
            HiddenField1.Value = user.Id.ToString();

            this.Label6.Text = user.Uid;
            tb_uname.Text = user.UName; //昵称
            if (user.Sex == "男")
            {
                RadioButton1.Checked = true;
                RadioButton2.Checked = false;
                RadioButton3.Checked = false;
            }
            else if (user.Sex == "女")
            {
                RadioButton1.Checked = false;
                RadioButton2.Checked = true;
                RadioButton3.Checked = false;
            }
            else if (user.Sex == "保密")
            {
                RadioButton1.Checked = false;
                RadioButton2.Checked = false;
                RadioButton3.Checked = true;
            }
            //将获取的数据截取作为一段数据
            if (user.Birthday=="")
            {

            }
            else
            {
            string sr = user.Birthday.Substring(0, 4);
            Hashtable Ht = new Hashtable();
            Ht.Add(sr, sr);
            DropDownList1.DataSource = Ht;
            DropDownList1.DataValueField = "key";
            DropDownList1.DataTextField = "value";
            DropDownList1.DataBind();

            string st = user.Birthday.Substring(5, 2);
            Hashtable Hh = new Hashtable();
            Hh.Add(st, st);
            DropDownList2.DataSource = Hh;
            DropDownList2.DataValueField = "key";
            DropDownList2.DataTextField = "value";
            DropDownList2.DataBind();

            string sy = user.Birthday.Substring(8, 2);
            Hashtable Hu = new Hashtable();
            Hu.Add(sy, sy);
            DropDownList3.DataSource = Hu;
            DropDownList3.DataValueField = "key";
            DropDownList3.DataTextField = "value";
            DropDownList3.DataBind();
                    
            }

            tb_phone.Text = user.Phone.ToString();
            tb_email.Text = user.Email;

           
        }

        protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
        {
            if(DropDownList2.SelectedValue == "2")
            {
                List<Dayy> dayys = dateManager.GetDaya();
                DropDownList3.DataSource = dayys;
                DropDownList3.DataValueField = "day";
                DropDownList3.DataTextField = "day";
                DropDownList3.DataBind();
            }
            else if(DropDownList2.SelectedValue == "7"|| DropDownList2.SelectedValue == "8"|| (int.Parse(DropDownList2.SelectedValue)%2== 1))
            {
                List<Dayy> dayys = dateManager.GetDay();
                DropDownList3.DataSource = dayys;
                DropDownList3.DataValueField = "day";
                DropDownList3.DataTextField = "day";
                DropDownList3.DataBind();
            }
            else
            {
                List<Dayy> dayys = dateManager.GetDayb();
                DropDownList3.DataSource = dayys;
                DropDownList3.DataValueField = "day";
                DropDownList3.DataTextField = "day";
                DropDownList3.DataBind();
            }
        }





        //  
        //    Response.Write("<script>alert("+upuser.UName+")</script>");
        //    marager.updataUsers(upuser, user.Id.ToString());

        //    this.tb_uname.Text = user.UName;
        //    if (RadioButton1.Checked == true)
        //    {
        //        user.Sex = "男";
        //    }
        //    else if (RadioButton2.Checked == true)
        //    {
        //        user.Sex = "女";

        //    }
        //    else if (RadioButton3.Checked == true)
        //    {
        //        user.Sex = "保密";
        //    };
        //    this.DropDownList1.SelectedIndex =
        //       DropDownList1.Items.IndexOf(DropDownList1.Items.FindByValue(user.Birthday.ToString()));
        //    this.tb_phone.Text = user.Phone.ToString();
        //    this.tb_email.Text = user.Email;


        //


    }
}